//检查用户名是否合法
function checkName(){
	var memberName = document.getElementById("memberName").value;
	if(memberName.length==0){	//用户名格式检查
		alert('姓名不能为空');
		document.getElementById("memberName").focus();
		return false;
	}else if(memberName.length>30){
		alert('姓名超长');
		document.getElementById("memberName").focus();
		return false;
	}
}

//检查身份证是否已经存在
function idNumberCanUse(){
	var idNumber = document.getElementById("idNumber").value;
	//调用ajax检查用户名是否重复
	//此处使用同步调用实现方式		
	var status = loadXMLDocSyn("/member/action/memberAction.php?op=check&idNumber="+idNumber);//使用绝对路径，以方便不同的页面调用
	if(status==200){
		if(xmlhttp.responseText>0){
			alert('该会员已经存在，如果已经失效，请恢复该会员资格！');
			document.getElementById("idNumber").focus();
			return false;
		}
	}

}

//检查证件号码是否为空
function checkidNumber(){
	var idNumber = document.getElementById("idNumber").value;
	if(idNumber.length==0){	
		alert('证件号不能为空');
		document.getElementById("idNumber").focus();
		return false;
	}
}

//检查会员卡号是否为空
function checkMemberNo(){
	if(document.getElementById("createNo").checked==false){
		var memberNo = document.getElementById("memberNo").value;
		if(memberNo.length==0){	
			alert('会员卡号不能为空');
			document.getElementById("memberNo").focus();
			return false;
		}
	}
}



//检查email是否合法
function checkEmail(){
	var email = document.getElementById("email").value;
	if(email.length>0){	
		var email = document.getElementById("email").value;
		var filter = (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
		if(!filter.test(email)||email.length>30){
			alert('请输入合法的email');
			return false;
		}
	}
}

//检查手机号码是否合法
function checkMobile(){
	var mobile = document.getElementById("mobile").value;
	var filter = (/^1[358]\d{9}$/);
	if(mobile==""){
		alert('电话号码不能为空');
		return false;
	}else{
		if(!filter.test(mobile)){
			alert('请输入合法的电话号码');
			return false;
		}
	}
}
//根据身份证号生成生日
function newBirthday(){
	var idNumber = document.getElementById("idNumber").value;
	var birthday = "";
	if(idNumber.length==18){
		birthday = idNumber.substr(6,4)+"-"+idNumber.substr(10,2)+"-"+idNumber.substr(12,2);
	}else if(idNumber.length==15){
		birthday = "19"+idNumber.substr(6,2)+"-"+idNumber.substr(8,2)+"-"+idNumber.substr(10,2);
	}
	document.getElementById("birthday").value = birthday;
}
//检查日期的格式
function checkDate(){ 
	var birthday = document.getElementById("birthday").value;
	if(birthday.length!=0){    
        var filter = (/^([1-2]\d{3})[\/|\-](0?[1-9]|10|11|12)[\/|\-]([1-2]?[0-9]|0[1-9]|30|31)$/ig);
        if(!filter.test(birthday)){
            alert('对不起，您输入的生日格式不正确!');  
        	return false;
        }
    }    
} 
//新增资料提交表单
function addFormSubmit(){
	if(checkName()==false||idNumberCanUse()==false||checkidNumber()==false
		||checkMemberNo()==false||checkEmail()==false||checkMobile()==false
		||checkDate()==false){
		return false;
	}
}

//修改资料提交表单
function editFormSubmit(){
	if(checkName()==false||checkidNumber()==false
		||checkMemberNo()==false||checkEmail()==false||checkMobile()==false
		||checkDate()==false){
		return false;
	}
}